package continuum.db.dao.impl;

import org.springframework.stereotype.Component;

import continuum.db.dao.DaoImpl;
import continuum.db.exceptions.DaoException;
import continuum.db.schema.entities.Charge;
import continuum.db.schema.entities.Employee;

@Component("chargeDao")
public class ChargeDao extends DaoImpl<Charge, Long> {

	public ChargeDao() {
		super(Charge.class);
	}

	@Override
	public Long insert(Charge newEntity) throws DaoException {
		Employee employee = newEntity.getEmployee();
		if (employee.getAuthorizedTasks().contains(newEntity.getTask()))
			return super.insert(newEntity);
		else
			throw new DaoException(
					"Tried to insert an unauthorized charge number for employee "
							+ employee.getFullName());
	}

}
